import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p002 from './p002';
import p003 from './p003';
import p005 from './p005';

export default async function a014(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 重新渲染p001
	const a1 = get('staff_no');
	const res1 = await nodejs<{
		res: Array<{}>; res3: Array<{
			inform_no: string, inform_title: string, inform_content: string,
			notification_time: number, pub_user_no: string, pub_user_name: string
		}>; res1: number
	}>('notification-notice/zj-000001/s005',
		{
			filter: {
				pn: 1,
				a: a1
			}
		});
	const arr1 = Array();
	const num = res1.res1[0].inform_title;
	for (let i = 0; i < num; i++) {
		arr1.push(res1.res3[i].inform_no);
	}
	const newres1 = res1.res3.map((n) => {
		return { ...n, receive_time: format(n.notification_time, 2) };
	});
	const res3 = await nodejs<{ dt: Array<{ inform_no: string, pub_user_no: string, pub_user_name: string }> }>('notification-notice/zj-000001/s006',
		{
			filter: {
				arr: arr1
			}
		});
	const newarr = newres1.map((n) => {
		for (let i = 0; i < res3.dt.length; i++) {
			if (n.inform_no === res3.dt[i].inform_no) {
				n.pub_user_no = res3.dt[i].pub_user_no,
					n.pub_user_name = res3.dt[i].pub_user_name;
				return n;
			}
		}
		n.pub_user_name = "";
		return n;
	});
	const dtData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dtNoData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const dtPn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p004"]');
	if (newres1.length > 0) {
		render(fd, newarr, p002, "p002", "inner");
		dtNoData.style.display = 'none';
		dtData.style.display = 'block';

		if (num > 20) {
			render(fd, num, p005, 'p005', "inner");
			dtPn.style.display = 'block';
		}
	} else {
		render(fd, "", p003, 'p003', 'inner');
		dtNoData.style.display = 'block';
		dtData.style.display = 'none';
		dtPn.style.display = 'none';
	}
}
